/*
 * TileMap.h
 *
 *  Created on: Sep 12, 2011
 *      Author: mengwei.chua
 */

#ifndef TILEMAP_H_
#define TILEMAP_H_

#include "parser/Map.h"
#include <string>
#include <map>
#include <deque>
#include <hge/hge.h>
#include <hge/hgesprite.h>

namespace projectcos
{
namespace tile
{

struct Tile
{
	unsigned int gid;
	bool flipHorizontal;
	bool flipVertical;
};

class TileMap
{
public:
	TileMap(HGE* hge);
	~TileMap();

	bool Load(std::string fileName);

	bool Render(const float x, const float y);

protected:
private:
	bool LoadTileTexture();
	bool ExtractLayers();
	HTARGET RenderToTarget(const std::deque<Tile>& tileList);

protected:
private:
	HGE* m_HGE;
	projectcos::tile::parser::Map m_Map;

	std::map<std::string, HTEXTURE> m_TileSetMap;
	std::map<unsigned int, hgeSprite> m_TileList;
	std::map< std::string, std::deque<Tile> > m_LayerMap;

	std::deque<HTARGET> m_TargetList;
};

} // tile
} // projectcos

#endif /* TILEMAP_H_ */
